package controller;

import org.w3c.dom.NamedNodeMap;

import entity.DecisionLinesEvent;

import server.ClientState;
import server.IProtocolHandler;
import xml.Message;

/**
 * 
 * @author Frank
 *
 */
public class CloseEventController implements IProtocolHandler{

	@Override
	public Message process(ClientState state, Message request) {
		entity.System system = entity.System.getInstance();
		NamedNodeMap map = request.contents.getFirstChild().getAttributes();
		String eventId = map.getNamedItem("id").getNodeValue();
		
		DecisionLinesEvent event = system.getEvent(eventId);
		event.setEventType("closed");
		system.updateEvent(eventId,event);
		
		String response = Message.responseHeader(request.contents.getAttributes().getNamedItem("id").getNodeValue());
		response += "<closeResponse /></response>";
		return new Message(response);
	}

}

/* Relevant .xsd
 
<xs:element name='closeRequest'> 
  <xs:complexType>
    <!-- force closure of a single event by moderator.-->
    <xs:attribute name='id'   type='xs:string' use='required'/>
  </xs:complexType>
</xs:element>

*/
